﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;

namespace l1cs.server.clientpackets
{
    public class C_Disconnect : ClientBasePacket
    {
        private const String _C_DISCONNECT = "[C] C_Disconnect";
        private static Logger _log = Logger.getLogger( typeof( C_Disconnect ).FullName );

        public C_Disconnect( byte[] decrypt, ClientThread client )
            : base( decrypt )
        {
            client.CharReStart( true );
            L1PcInstance pc = client.getActiveChar();
            if ( pc != null )
            {

                _log.fine( "Disconnect from: " + pc.getName() );

                ClientThread.quitGame( pc );

                lock ( pc )
                {
                    pc.logout();
                    client.setActiveChar( null );
                }
            }
            else
            {
                _log.fine( "Disconnect Request from Account : "
                        + client.getAccountName() );
            }
        }

        override
        public String getType()
        {
            return _C_DISCONNECT;
        }
    }
}
